//index.js
//获取应用实例

const app = getApp()
//引入文件
var WxParse = require('../../wxParse/wxParse.js');

Page({
  data: {

    recommend:[],
    hasRecommend:false
  },
  onLoad:function(e){
    var that=this;
    this.setData({
      id:e.id,
      title: e.name
    })
    wx.setNavigationBarTitle({
      title: that.data.title
    })
    
    //推荐数据
    wx.request({
      url: 'https://soya.91soya.com/api/typeinfo/' + e.id,
      method: "get",
      success: function (res) {
        var resp = res.data;
        if(resp!=[]){
          var a = [];
          for (var i = 0; i < resp.length; i++) {
            a[i] = { id: resp[i].id, pid: resp[i].pid, pImg: " https://soya.91soya.com/uploads/" + resp[i].p_img, tImg: " https://soya.91soya.com/uploads/" + resp[i].t_img, tName: resp[i].tname, pName: resp[i].pname, pIntr: resp[i].title, priceNow: resp[i].price, priceBefore: resp[i].y_price}
          }
          that.setData({
            recommend: a,
            hasRecommend:true
          })
        }
      },
      fail: function () {
        console.log("推荐数据加载失败")
      }
    })
  },
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    var that = this;
    // 显示加载图标
    // wx.showLoading({
    //   title: '玩命加载中',
    // })
    this.data.page+=1;
    var page = this.data.page
    wx.request({
      url: 'https://soya.91soya.com/api/product/?page='+page,
      method: "GET",
      success: function (res) {
        var resp=res.data.data;
        var a=[];
        if(resp!==[]){
          var pro2_list = that.data.recommend;
          for (var i = 0; i < resp.length; i++) {
            pro2_list.push({ id: resp[i].id, pid: resp[i].pid, pImg: " https://soya.91soya.com/uploads/" + resp[i].p_img, tImg: " https://soya.91soya.com/uploads/" + resp[i].t_img, tName: resp[i].tname, pName: resp[i].pname, pIntr: resp[i].title, priceNow: resp[i].price, priceBefore: resp[i].y_price })
          }
          // 设置数据
          that.setData({
            recommend: pro2_list
          })
        } else if (resp==[]&&this.data.isBottom==false){}
        // // 隐藏加载框
        // wx.hideLoading();
      },
      fail:function(res){
        console.log("下拉加载失败")
        // // 隐藏加载框
        // wx.hideLoading();
      }
    })

  },

  // 分享
  onShareAppMessage:function(){
    var that = this;
    return {
      title: that.data.title,
      // desc: '来来来一起种植牙啊',
      path: '/pages/type/type?id='+that.data.id
    }
  }


})
